home *** CD-ROM | disk | FTP | other *** search
/ The Atari Compendium / The Atari Compendium (Toad Computers) (1994).iso / files / prgtools / gnustuff / tos / futils / futils~1 / man / manpages.zoo / expr.1 < prev    next >
Encoding:
Text File  |  1991-11-13  |  2.9 KB  |  133 lines

  1.  
  2.  
  3.  
  4. EXPR(1L)                                                 EXPR(1L)
  5.  
  6.  
  7.  
  8. NAME
  9.      expr - evaluate expressions
  10.  
  11. SYNOPSIS
  12.      expr expression...
  13.  
  14. DESCRIPTION
  15.      This manual page documents the GNU version of expr.  expr
  16.      evaluates an expression and writes the result on its stan-
  17.      dard output.  Each token of the expression must be a
  18.      separate argument.  Operands are either numbers or strings.
  19.      Strings are not quoted for expr, though you may need to
  20.      quote them to protect them from the shell.  expr coerces
  21.      anything appearing in an operand position to an integer or a
  22.      string depending on the operation being applied to it.
  23.  
  24.      The operators (in order of increasing precedence) are:
  25.  
  26.      |    yields its first argument if it is neither null nor 0,
  27.           otherwise its second argument.  This is the usual `or'
  28.           operation.
  29.  
  30.      &    yields its first argument if neither argument is null
  31.           or 0, otherwise 0.
  32.  
  33.      < <= = != >= >
  34.           compare their arguments and return `1' if the relation
  35.           is true, 0 otherwise.  expr tries to coerce both argu-
  36.           ments to numbers and do a numeric comparison; if it
  37.           fails when trying to coerce either argument it then
  38.           does a lexicographic comparison.
  39.  
  40.      + -  perform arithmetic operations.  Both arguments are
  41.           coerced to numbers; an error occurs if this cannot be
  42.           done.
  43.  
  44.      * / %
  45.           perform arithmetic operations (`%' is the remainder
  46.           operation, as in C).  Both arguments are coerced to
  47.           numbers; an error occurs if this cannot be done.
  48.  
  49.      :    performs pattern matching.  Its arguments are coerced
  50.           to strings and the second one is considered to be a
  51.           regular expression, with a `^' implicitly added at the
  52.           beginning.  The first argument is then matched against
  53.           this regular expression.  If the match succeeds and
  54.           part of the string is enclosed in `\(' and `\)', that
  55.           part is the value of the : expression; otherwise an
  56.           integer whose value is the number of characters matched
  57.           is returned.  If the match fails, the :  operator
  58.           returns the null string if `\(' and `\)' are used, oth-
  59.           erwise 0.  Only one `\(' and `\)' pair can be used.
  60.  
  61.  
  62.  
  63. Page 1
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70. EXPR(1L)                                                 EXPR(1L)
  71.  
  72.  
  73.  
  74.      Parentheses are used for grouping in the usual manner.
  75.  
  76.      Examples:
  77.  
  78.      To add 1 to the shell variable _✓a:
  79.  
  80.           a=`expr $a + 1`
  81.  
  82.      To find the filename part of the pathname stored in variable
  83.      _✓a, which may or may not contain `/':
  84.  
  85.           expr $a : '.*/\(.*\)' '|' $a
  86.  
  87.      Note the quoted shell metacharacters.
  88.  
  89.      expr returns the following exit status:
  90.  
  91.      0 if the expression is neither null nor 0,
  92.      1 if the expression is null or 0,
  93.      2 for invalid expressions.
  94.  
  95.  
  96.  
  97.  
  98.  
  99.  
  100.  
  101.  
  102.  
  103.  
  104.  
  105.  
  106.  
  107.  
  108.  
  109.  
  110.  
  111.  
  112.  
  113.  
  114.  
  115.  
  116.  
  117.  
  118.  
  119.  
  120.  
  121.  
  122.  
  123.  
  124.  
  125.  
  126.  
  127.  
  128.  
  129. Page 2
  130.  
  131.  
  132.  
  133.